package com.ruoyi.web.controller.marketing;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.system.domain.ActivityOperationRecord;
import com.ruoyi.system.dto.ActivityOperationRecordQueryDTO;
import com.ruoyi.system.service.IActivityOperationRecordService;
import com.ruoyi.system.util.AbdulEmptyUtils;
import com.ruoyi.system.util.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/activity-record")
@Api(tags = "活动操作记录管理")
public class ActivityOperationRecordController {

    @Autowired
    private IActivityOperationRecordService recordService;

    /**
     * 分页查询活动操作记录
     */
    @GetMapping("/page")
    @ApiOperation("分页查询活动操作记录")
    public BaseResponse<IPage<ActivityOperationRecord>> page(@RequestBody ActivityOperationRecordQueryDTO queryDTO) {
        // 创建分页对象
        Page<ActivityOperationRecord> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize());
        // 创建查询条件
        LambdaQueryWrapper<ActivityOperationRecord> wrapper = Wrappers.lambdaQuery();

        if (queryDTO.getMarketingActivityCode() != null && !queryDTO.getMarketingActivityCode().isEmpty()) {
            wrapper.eq(ActivityOperationRecord::getMarketingActivityCode, queryDTO.getMarketingActivityCode());
        }
        wrapper.eq(!AbdulEmptyUtils.isEmpty(queryDTO.getOperationType()), ActivityOperationRecord::getOperationType, queryDTO.getOperationType());

        if (queryDTO.getStartDate() != null && queryDTO.getEndDate() != null) {
            wrapper.between(ActivityOperationRecord::getCreateTime, queryDTO.getStartDate(), queryDTO.getEndDate());
        }
        wrapper.eq(queryDTO.getMarketingType() != null, ActivityOperationRecord::getMarketingType, queryDTO.getMarketingType());
        // 执行分页查询
        IPage<ActivityOperationRecord> resultPage = recordService.page(page, wrapper);
        return BaseResponse.success(resultPage);
    }


}
